import configparser
import os

_conf = configparser.ConfigParser()
_f = "conf/app.ini"

assert os.path.isfile(_f), "配置文件【app.ini】不存在"
_conf.read(_f, encoding="utf-8")


try: 
    app = _conf["app"]
    DEBUG = app.getboolean("DEBUG", True)
    SECRET_KEY = app.get("SECRET_KEY", "kjhgf$#@5yui234")
except:
    DEBUG = True
    SECRET_KEY = "gf$#@5yui2"

    

try: 
    server = _conf["server"]
    PORT = server.getint("PORT", 8080)
    READ_TIMEOUT = server.getint("READ_TIMEOUT", 60)
    WRITE_TIMEOUT = server.getint("WRITE_TIMEOUT", 60)
except:
    PORT = 8080
    READ_TIMEOUT = 60
    WRITE_TIMEOUT = 60


try:
    database = _conf["database"]
    SQLALCHEMY_DATABASE_URI = database.get("SQLALCHEMY_DATABASE_URI")
    SQLALCHEMY_TRACK_MODIFICATIONS = database.getboolean("SQLALCHEMY_TRACK_MODIFICATIONS")
    SQLALCHEMY_ECHO = database.getboolean("SQLALCHEMY_ECHO")
except:
    SQLALCHEMY_DATABASE_URI = None
    SQLALCHEMY_TRACK_MODIFICATIONS = None
    SQLALCHEMY_ECHO = None

